using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class Shining : MonoBehaviour
{
	[SerializeField]
	private float width = 0.2f;

	[SerializeField]
	private float shiningTime = 1f;

	private Image image;

	private WaitForSeconds waitForSeconds;

	private void Awake()
	{
		image = GetComponent<Image>();
		waitForSeconds = new WaitForSeconds(1f);
	}

	private void OnEnable()
	{
		StartCoroutine(Shine());
	}

	private IEnumerator Shine()
	{
		while (true)
		{
			float currentTime = 0f;
			float speed = 1f / shiningTime;
			image.material.SetFloat("_Width", width);
			while (currentTime <= shiningTime)
			{
				currentTime += Time.deltaTime;
				float value = Mathf.Lerp(0f, 1f, speed * currentTime);
				image.material.SetFloat("_TimeController", value);
				yield return null;
			}
			yield return waitForSeconds;
			image.material.SetFloat("_Width", 0f);
		}
	}
}
